<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>超人气热销好物</title>

    <!-- flexible.js -->
    <script>
        !function () { var a = "@charset \"utf-8\";html{color:#000;background:#fff;overflow-y:scroll;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%}html *{outline:0;-webkit-text-size-adjust:none;-webkit-tap-highlight-color:rgba(0,0,0,0)}html,body{font-family:sans-serif}body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,textarea,p,blockquote,th,td,hr,button,article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section{margin:0;padding:0}input,select,textarea{font-size:100%}table{border-collapse:collapse;border-spacing:0}fieldset,img{border:0}abbr,acronym{border:0;font-variant:normal}del{text-decoration:line-through}address,caption,cite,code,dfn,em,th,var{font-style:normal;font-weight:500}ol,ul{list-style:none}caption,th{text-align:left}h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:500}q:before,q:after{content:''}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sup{top:-.5em}sub{bottom:-.25em}a:hover{text-decoration:underline}ins,a{text-decoration:none}", b = document.createElement("style"); if (document.getElementsByTagName("head")[0].appendChild(b), b.styleSheet) b.styleSheet.disabled || (b.styleSheet.cssText = a); else try { b.innerHTML = a } catch (c) { b.innerText = a } }(); !function (a, b) { function c() { var b = f.getBoundingClientRect().width; b / i > 540 && (b = 540 * i); var c = b / 10; f.style.fontSize = c + "px", k.rem = a.rem = c } var d, e = a.document, f = e.documentElement, g = e.querySelector('meta[name="viewport"]'), h = e.querySelector('meta[name="flexible"]'), i = 0, j = 0, k = b.flexible || (b.flexible = {}); if (g) { var l = g.getAttribute("content").match(/initial\-scale=([\d\.]+)/); l && (j = parseFloat(l[1]), i = parseInt(1 / j)) } else if (h) { var m = h.getAttribute("content"); if (m) { var n = m.match(/initial\-dpr=([\d\.]+)/), o = m.match(/maximum\-dpr=([\d\.]+)/); n && (i = parseFloat(n[1]), j = parseFloat((1 / i).toFixed(2))), o && (i = parseFloat(o[1]), j = parseFloat((1 / i).toFixed(2))) } } if (!i && !j) { var p = (a.navigator.appVersion.match(/android/gi), a.navigator.appVersion.match(/iphone/gi)), q = a.devicePixelRatio; i = p ? q >= 3 && (!i || i >= 3) ? 3 : q >= 2 && (!i || i >= 2) ? 2 : 1 : 1, j = 1 / i } if (f.setAttribute("data-dpr", i), !g) if (g = e.createElement("meta"), g.setAttribute("name", "viewport"), g.setAttribute("content", "initial-scale=" + j + ", maximum-scale=" + j + ", minimum-scale=" + j + ", user-scalable=no"), f.firstElementChild) f.firstElementChild.appendChild(g); else { var r = e.createElement("div"); r.appendChild(g), e.write(r.innerHTML) } a.addEventListener("resize", function () { clearTimeout(d), d = setTimeout(c, 300) }, !1), a.addEventListener("pageshow", function (a) { a.persisted && (clearTimeout(d), d = setTimeout(c, 300)) }, !1), "complete" === e.readyState ? e.body.style.fontSize = 12 * i + "px" : e.addEventListener("DOMContentLoaded", function () { e.body.style.fontSize = 12 * i + "px" }, !1), c(), k.dpr = a.dpr = i, k.refreshRem = c, k.rem2px = function (a) { var b = parseFloat(a) * this.rem; return "string" == typeof a && a.match(/rem$/) && (b += "px"), b }, k.px2rem = function (a) { var b = parseFloat(a) / this.rem; return "string" == typeof a && a.match(/px$/) && (b += "rem"), b } }(window, window.lib || (window.lib = {}));
    </script>

    <style>
        [v-cloak] {
            display: none
        }

        body,
        html {
            min-height: 100vh;
            background: #8731ee;
            padding: 0;
            margin: 0
        }

        .fictitious-container {
            background: url(http://img.bc.haodanku.com/openapi/1599269176) no-repeat;
            background-size: 100%;
            padding-top: 4.05797rem
        }

        .fictitious-head {
            padding: .28985rem .28985rem 0;
            box-sizing: border-box;
        }

        .fictitious-nav {
            background: #FFFFFF;
            display: -webkit-flex;
            display: flex;
            border-radius: 0.16rem;
            overflow-x: auto;
        }

        .fictitious-nav li {
            position: relative;
            /* min-width: 2.1333rem; */
            /* width: 100%; */
            font-size: .33816rem;
            /* font-weight: 700; */
            text-align: center;
            color: #333333;
            display: -webkit-inline-flex;
            display: inline-flex;
            -webkit-align-items: center;
            align-items: center;
            -webkit-justify-content: center;
            justify-content: center;
            -webkit-flex-shrink: 0;
            flex-shrink: 0;
            padding: 0.2667rem 0.32rem;
            letter-spacing: 0.0267rem;
            overflow: hidden;
            -webkit-user-select: none;
            user-select: none
        }

        li.nav-active {
            font-weight: 600;
            color: #8731ee;
        }

        li.nav-active::before {
            content: "";
            position: relative;
            top: 0.0267rem;
            left: 0;
            width: 0.36rem;
            height: 0.36rem;
            background: url(http://img.bc.fqapps.com/fudai1d328d484356b367b0f7d9a8be512d07.png) no-repeat;
            background-size: 100%;
            display: block;
        }

        .fictitious-content {
            min-height: -webkit-calc(100vh - 5.26570rem);
            min-height: calc(100vh - 5.26570rem);
            background: #8731ee;
            /* border-top: 2px solid #6900e5 */
        }

        .fictitious-inner {
            position: relative;
            padding: .28985rem
        }

        .goods-inner {
            background: #fff;
            display: -webkit-flex;
            display: flex;
            padding: .28985rem;
            margin-bottom: .28985rem;
            border-radius: 0.16rem;
        }

        .goods-inner:last-child {
            margin-bottom: 0
        }

        .goods-img {
            width: 2.89855rem;
            height: 2.89855rem;
            display: block;
            border-radius: 0.16rem;
        }

        .goods-info {
            width: -webkit-calc(100% - 2.89855rem);
            width: calc(100% - 2.89855rem);
            display: -webkit-flex;
            display: flex;
            -webkit-flex-direction: column;
            flex-direction: column;
            -webkit-align-items: flex-start;
            align-items: flex-start;
            -webkit-justify-content: space-between;
            justify-content: space-between;
            padding-left: .28985rem;
            box-sizing: border-box
        }

        /* .goods-title{width:100%;font-size:.33816rem;color:#333;word-wrap:normal;text-overflow:ellipsis;white-space:nowrap;overflow:hidden} */
        .goods-title {
            width: 100%;
            font-size: .33816rem;
            color: #333
        }

        .goods-number {
            font-size: 0.33816rem;
            color: #8731ee;
            display: inline-block;
            padding: .04830rem .24154rem;
            -webkit-user-select: none;
            user-select: none
        }

        .goods-number>em {
            font-weight: 600;
            padding: 0 0.0533rem;
        }

        .goods-price {
            width: 100%;
            display: -webkit-inline-flex;
            display: inline-flex;
            -webkit-align-items: center;
            align-items: center;
            -webkit-justify-content: space-between;
            justify-content: space-between
        }

        .goods-flexend {
            -webkit-justify-content: flex-end;
            justify-content: flex-end;
        }

        .price-inner {
            font-size: .33816rem;
            color: #8731ee
        }

        .spike {
            font-size: .43478rem
        }

        .goods-buy {
            min-width: 36%;
            font-size: 0.32rem;
            text-align: center;
            color: #fff;
            background: #8731EE;
            padding: 0.1333rem 0;
            border-radius: 1000px;
            cursor: pointer;
            -webkit-user-select: none;
            user-select: none;
            box-sizing: border-box
        }

        .loading {
            position: absolute;
            top: 30px;
            left: 50%;
            -webkit-transform: translateX(-50%);
            transform: translateX(-50%)
        }

        .loading .outer {
            width: 50px;
            height: 50px;
            border: 5px solid #fff;
            border-top-color: transparent;
            border-bottom-color: transparent;
            border-radius: 1000px;
            opacity: .9;
            -webkit-animation: spin-right .5s linear infinite normal;
            animation: spin-right .5s linear infinite normal;
            margin: 0 auto
        }

        .loading .inner {
            position: absolute;
            top: 9px;
            left: -webkit-calc(50% - 20px);
            left: calc(50% - 20px);
            width: 30px;
            height: 30px;
            border: 5px solid #fff;
            border-radius: 1000px;
            border-left-color: transparent;
            border-bottom-color: transparent;
            opacity: .9;
            -webkit-animation: spin-left .5s linear infinite normal;
            animation: spin-left .5s linear infinite normal
        }

        .loading-text {
            font-size: .38647rem;
            color: #fff;
            margin-top: 12px
        }

        .fictitious-head-fixed {
            position: fixed;
            top: 0;
            width: 100%;
            padding: 0;
            z-index: 100;
        }

        .fictitious-head-fixed>.fictitious-nav {
            border-radius: 0;
        }

        .fictitious-content-paddingTop {
            padding-top: 1.15942rem
        }

        .fictitious-tips {
            display: block;
            font-size: .33816rem;
            text-align: center;
            color: #fff;
            letter-spacing: 1px;
            -webkit-user-select: none;
            user-select: none
        }

        .goods-share {
            width: 100%;
            display: -webkit-flex;
            display: flex;
            -webkit-align-items: center;
            align-items: center;
            -webkit-justify-content: space-between;
            justify-content: space-between;
        }

        .share-money {
            font-size: 0.33816rem;
            color: #FFFFFF;
            background: #F2A22C;
            padding: .09661rem 0.28986rem;
            border-top-left-radius: 1000px;
            border-bottom-left-radius: 1000px
        }

        /* .share-money>em{font-size:15.99986px} */

        @-webkit-keyframes spin-right {
            0% {
                -webkit-transform: rotate(0);
                transform: rotate(0);
                opacity: .2
            }

            50% {
                -webkit-transform: rotate(180deg);
                transform: rotate(180deg);
                opacity: 1
            }

            100% {
                -webkit-transform: rotate(360deg);
                transform: rotate(360deg);
                opacity: .2
            }
        }

        @keyframes spin-right {
            0% {
                -webkit-transform: rotate(0);
                transform: rotate(0);
                opacity: .2
            }

            50% {
                -webkit-transform: rotate(180deg);
                transform: rotate(180deg);
                opacity: 1
            }

            100% {
                -webkit-transform: rotate(360deg);
                transform: rotate(360deg);
                opacity: .2
            }
        }

        @-webkit-keyframes spin-left {
            0% {
                -webkit-transform: rotate(0);
                transform: rotate(0);
                opacity: .2
            }

            50% {
                -webkit-transform: rotate(-180deg);
                transform: rotate(-180deg);
                opacity: 1
            }

            100% {
                -webkit-transform: rotate(-360deg);
                transform: rotate(-360deg);
                opacity: .2
            }
        }

        @keyframes spin-left {
            0% {
                -webkit-transform: rotate(0);
                transform: rotate(0);
                opacity: .2
            }

            50% {
                -webkit-transform: rotate(-180deg);
                transform: rotate(-180deg);
                opacity: 1
            }

            100% {
                -webkit-transform: rotate(-360deg);
                transform: rotate(-360deg);
                opacity: .2
            }
        }

        .showToast {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            display: block;
            z-index: 100
        }

        .showToast>span {
            position: relative;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            height: 36px;
            line-height: 36px;
            font-size: 14px;
            color: #fff;
            background: rgba(0, 0, 0, .6);
            display: inline-block;
            padding: 0 24px;
            border-radius: 4px
        }

        .goods-coupon {
            height: 0.5867rem;
            display: -webkit-inline-flex;
            display: inline-flex;
            -webkit-align-items: center;
            align-items: center;
            border: 1px solid #8731ee;
            box-sizing: border-box;
        }

        .coupon-text {
            line-height: 0.5867rem;
            font-size: 0.32rem;
            background: #8731ee;
            color: #FFFFFF;
            padding: 0 0.1067rem;
        }

        .coupon-inner {
            line-height: 0.5867rem;
            font-size: 0.3733rem;
            color: #8731ee;
            padding: 0 0.1067rem;
        }

        .coupon-inner>i {
            font-style: normal;
            font-size: 0.32rem;
        }

        .goods-spike {
            display: -webkit-inline-flex;
            display: inline-flex;
            -webkit-align-items: flex-end;
            align-items: flex-end;
        }

        .spike-text {
            font-size: 0.3467rem;
            color: #8731ee;
        }

        .spike-money {
            position: relative;
            top: 0.0267rem;
            font-size: 0.4533rem;
            font-weight: 600;
            color: #8731ee;
        }
    </style>
</head>

<body>
    <div id="fictitious_app" v-cloak>
        <div class="fictitious-container">
            <!-- 导航栏 -->
            <div class="fictitious-head" :class="{'fictitious-head-fixed': isHeadFixed}">
                <ul class="fictitious-nav">
                    <li v-for="nav in fictitiousNav" :class="{'nav-active': nav.category_id == current.currentIndex}" @click="slideNav(nav)">{{nav.category_name}}</li>
                </ul>
            </div>

            <!-- 商品信息 -->
            <div class="fictitious-content" :class="{'fictitious-content-paddingTop': isHeadFixed}">
                <div class="fictitious-inner">
                    <div class="goods-inner" v-for="(item, index) in itemsData" :key="index" :id="'shoplist' + item.itemid" @click="goodsBuy(item)" v-if="!showLoading">
                        <img :src="item.itempic" alt="" class="goods-img">
                        <div class="goods-info">
                            <p class="goods-title">{{item.itemshorttitle}}</p>
                            <div class="goods-price" :class="{'goods-flexend': item.couponmoney <= 0}">
                                <span class="goods-coupon" v-if="item.couponmoney > 0">
                                    <span class="coupon-text">券</span>
                                    <span class="coupon-inner"><i>￥</i>{{ item.couponmoney }}</span>
                                </span>
                                <span class="goods-number">已抢<em>{{ item.itemsale }}</em>件</span>
                            </div>
                            <div class="goods-share">
                                <span class="goods-spike">
                                    <span class="spike-text">券后价￥</span>
                                    <em class="spike-money">{{ item.itemendprice }}</em>
                                </span>
                                <span class="goods-buy">立即抢购</span>
                            </div>
                        </div>
                    </div>

                    <!-- 加载中动画 -->
                    <div class="loading" v-if="showLoading">
                        <div class="outer"></div>
                        <div class="inner"></div>
                        <div class="loading-text">数据加载中，请稍后...</div>
                    </div>

                    <!-- 到底提示 -->
                    <div class="fictitious-tips" v-if="showTips">没有更多商品了喔！</div>
                </div>
            </div>
        </div>
    </div>

    <script src="https://lib.baomitu.com/jquery/3.4.1/jquery.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.min.js"></script>
    <script src="https://lib.baomitu.com/clipboard.js/2.0.4/clipboard.min.js"></script>
    <script src="https://lib.baomitu.com/layer/2.3/layer.js"></script>
    <script>
        var fictitiousApp = new Vue({
            el: '#fictitious_app',
            data: {
                // 导航栏
                fictitiousNav: [],
                // 商品信息
                itemsData: [],
                current: {
                    currentIndex: '',       // 当前导航栏下标
                    currentPage: 1,         // 当前分页
                    currentType: ''         // 当前分类
                },
                showLoading: true,          // 加载中动画
                showTips: false,            // 无商品提示
                ajaxSwitch: true,           // 控制是否可以发起请求
                isHeadFixed: false,          // 导航栏是否固定
            },
            created: function () {
                this.getCategory();
                this.getMaterialData();

                var self = this;
                window.addEventListener('scroll', function () {
                    var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;

                    // 固定导航栏
                    (scrollTop / 41.4 >= 4.10628) ? self.isHeadFixed = true : self.isHeadFixed = false;

                    // 滑到底部自动加载下一页数据
                    if (scrollTop + window.innerHeight >= document.body.offsetHeight - 200) {
                        if (self.ajaxSwitch == true) {
                            self.ajaxSwitch = false;
                            self.getMaterialData();
                        }
                    };
                });
            },
            methods: {
                // 获取类目
                getCategory: function () {
                    var that = this;

                    $.ajax({
                        url: 'https://api.haodanku.com/activity/tb_items_material_category',
                        type: 'GET',
                        data: {},
                        dataType: 'json',
                        async: false
                    }).done(function (res) {
                        if (res.code == 200) {
                            that.fictitiousNav = res.data;
                            that.current.currentIndex = res.data[0].category_id;
                        }
                    })
                },

                /**
                 * 获取商品数据
                 * @param min_id
                 * @param cat_id
                */
                getMaterialData: function () {
                    var that = this,
                        data = {
                            apikey: 'sylar',     //需修改-API-地址：https://www.haodanku.com/api/detail/show/43.html
                            cat_id: that.current.currentIndex,
                            back: 10,
                            min_id: that.current.currentPage,
                        };

                    $.ajax({
                        url: 'https://v2.api.haodanku.com/tb_items_material_data',
                        type: 'GET',
                        data: data,
                        dataType: 'json',
                        // async: false
                    }).done(function (res) {
                        if (res.code == 200) {
                            setTimeout(function () {
                                res.data.forEach(function (val) {
                                    that.itemsData.push(val);
                                });
                                that.showLoading = false;
                                that.ajaxSwitch = true;
                                that.current.currentPage++;

                                // 无更多数据
                                if (res.data.length < 9) {
                                    that.showTips = true;
                                    that.ajaxSwitch = false;
                                }
                            }, 300)
                        } else {
                            that.getMaterialData()
                        }
                    })
                },

                // 切换版块
                slideNav: function (nav) {
                    var self = this;

                    self.showLoading = true;
                    self.showTips = false;
                    // 清空当前已有数据
                    self.itemsData = [];
                    self.current.currentPage = 1;
                    self.ajaxSwitch = false;
                    self.current.currentIndex = nav.category_id;
                    self.current.currentType = nav.category_name;
                    self.getMaterialData();
                },

                /**
                 * 立即抢购
                 * @param item: 商品数据
                */
                goodsBuy: function (item) {
                    var that = this,
                        data = {
                            apikey: 'sylar',     //需修改-高佣转链API-地址：https://www.haodanku.com/api/detail/show/15.html
                            tb_name: 'tb370655212',     //需修改
                            pid: 'mm_1520060136_2232550319_111181400478',     //需修改
                            relation_id: '',     //需修改
                            itemid: item.itemid,
                            get_taoword: 1,
                            title: item.itemshorttitle
                        };

                    $.ajax({
                        url: 'https://v2.api.haodanku.com/ratesurl',
                        type: 'POST',
                        data: data,
                        dataType: 'json',
                        async: false
                    }).done(function(res) {
                        if (res.code == 1) {
                            $('#shoplist' + item.itemid).attr('data-word', res.data.taoword);
                        } else {
                            layer.msg(res.msg, {
                                time: 1200
                            })
                        }
                    });

                    var clipboard = new ClipboardJS('#shoplist' + item.itemid, {
                        text: function () {
                            return $('#shoplist' + item.itemid).attr('data-word');
                        }
                    });

                    clipboard.on('success', function (e) {
                        // console.log('复制成功');
                        layer.msg('复制口令成功，请打开淘宝领取！', {
                            time: 1200
                        })
                    });

                    clipboard.on('error', function (e) {
                        layer.msg('复制口令失败', {
                            time: 1200
                        })
                    })
                },
            }
        });
    </script>
</body>

</html>